<?php
namespace App\Exceptions;

use Exception;
use Illuminate\Support\Facades\Log;
use Throwable;

class CdjException extends Exception
{
    protected $info;
    protected $code;
    protected $data;

    public function __construct($message = "", $code = 0, $data = [], Throwable $previous = null)
    {
        parent::__construct($message, $code, $previous);

        $this->info = $message;
        $this->code = $code;
        $this->data = $data;
    }

    public function report()
    {

    }

    public function render()
    {
        $result = [
            'success' => false,
            'data' => $this->data ?: new \stdClass(),
            'errorMessage' => $this->info,
            'errorCode' => $this->code,
        ];

        return response()->json($result);
    }
}
